package net.cyndeline.scalarlib.entityComponent.miranda.util

import scala.collection.mutable

/**
 * Keeps track of available id's and allows the user to free up old ids for reuse.
 */
class IdPool {
  private var id = 0
  private val availableForReuse = mutable.Queue[Int]()

  def free(id: Int) {
    availableForReuse.enqueue(id)
  }

  def nextId: Int = if (availableForReuse.isEmpty) {
    id += 1
    id - 1
  } else {
    availableForReuse.dequeue()
  }

}
